"use strict";
import { mapGetters } from "vuex"
import store from "../store";
export default {
	
	data() {
		return {
			userListAll:[],
			userList:[],
			systemList:[],
			systemListAll:[],
			orgListAll:[]
		}
	},
	created() {
		this.userListAll = store.getters.getUserList();
		this.systemListAll = store.getters.getSystemList();
		this.orgListAll = store.getters.getOrgList();
		this.userList =this.userListAll; 
		this.systemList = this.systemListAll;
		
	},
	computed: {
		...mapGetters(["dict","vaildPermission"]),
	},
	filters:{
		dictName(itemCode,dictCode){
			let item = store.getters.getDataDictionaryItem(dictCode,itemCode);
			if(item!=null){
				return item.itemName
			}else{
				return "";
			}
		},
		dictCodeName(itemCode,dictCode){
			let dataDictionaryItem =  store.getters.getDataDictionaryItem(dictCode,itemCode);
			if(dataDictionaryItem != null){
				return dataDictionaryItem.itemCode +"-"+dataDictionaryItem.itemName;
			}
		},
		getUserChinesName(userName){
			let user =  store.getters.getUser(userName);
			if(user != null){
				return user.userChineseName;
			}
		},
		getSystemName(systemNo){
			let system =  store.getters.getSystem(systemNo);
			if(system != null){
				return system.systemName;
			}
		},
		
		getOrgNameBySystemNo(systemNo){
			let system =  store.getters.getSystem(systemNo);
			console.info(system)
			if(system != null){
				let orgNo = system.systemOrg;
					
				if(orgNo!=null && orgNo!= ''){
					let org =  store.getters.getOrg(orgNo);
					
					if(org!=null){
						return org.orgName;
					}
					
				}
			}
			
			return "";
		},
		
		getOrgNameByOrgCode(orgNo){
				if(orgNo!=null && orgNo!= ''){
					let org =  store.getters.getOrg(orgNo);
					console.info(org)
					if(org!=null){
						return org.orgName;
					}
					
				}
			return "";
		}
		
		
	},
	
	methods:{
		
		handleClose(){
			
		},
		getSystemName(systemNo){
			let system =  store.getters.getSystem(systemNo);
			if(system != null){
				return system.systemName;
			}
		},
		getUsers(val){
			if(val != ''){
				this.userList =  this.userListAll.filter(item=>{
					  return item.userName.indexOf(val) !=-1  || item.userChineseName.indexOf(val) !=-1;
				  })
				  this.userList = this.userList.filter((item,index)=>{
					  return index <6;
				  });
			}else{
				this.userList =this.userListAll;
			}
			
		},
		
		getsystems(val){
			if(val != ''){
				this.systemList =  this.systemListAll.filter(item=>{
					  return item.systemNo.indexOf(val) !=-1  || item.systemName.indexOf(val) !=-1;
				  })
				
			}else{
				this.systemList = this.systemListAll;
			}
			
		},
	
		dictName(itemCode,dictCode){
		let item = store.getters.getDataDictionaryItem(dictCode,itemCode);
		if(item!=null){
			return item.itemName
		}else{
			return "";
		}
	},
		
		
		reset(){
			this.$refs["form"].resetFields();
		},
		
		fetchProtocal(queryString,cb){
			var protocals = [{value:"socket/xml"},{value:"http/json"},{value:"http/soap"},{value:"https/json"},{value:"定长"},{value:"分隔符"},{value:"其他"}];
			
			var protocals1 =
			protocals1  = queryString? protocals.filter(item=>{
				return item.value.indexOf(queryString)>-1;
			}):protocals;
			cb(protocals1);
		},
		
	}
	
}
